package com.kaiyiweitong.tongxing.activity.my.my_money;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.kaiyiweitong.tongxing.R;
import com.kaiyiweitong.tongxing.base.BaseActivity;
import com.kaiyiweitong.tongxing.widget.ChooseBankDialog;
import com.weigan.loopview.LoopView;
import com.weigan.loopview.OnItemSelectedListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/12/18 0018.
 */

public class AddBankCardActivity extends BaseActivity {
    @Bind(R.id.card_person)
    EditText mCardPerson;
    @Bind(R.id.bank_card)
    TextView mBankCard;
    @Bind(R.id.card_num)
    EditText mCardNum;
    @Bind(R.id.finish)
    TextView mFinish;
    private ChooseBankDialog mChooseBankDialog;
    private int mCurrentIndex = -1;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_bank_card);
        ButterKnife.bind(this);
        mChooseBankDialog = new ChooseBankDialog(this);
    }

    @OnClick(R.id.bank_card)
    public void onViewClicked() {
        showDialog();
    }

    private void showDialog() {
        mChooseBankDialog.show();
        LoopView loopView = mChooseBankDialog.findViewById(R.id.loopView);

        final List<String> list = new ArrayList<>();
        list.add("中国银行");
        list.add("中国建设银行");
        list.add("中国交通银行");
        list.add("中国工商银行");
        list.add("中国农业银行");

        loopView.setItems(list);
        loopView.setInitPosition(0);
        mCurrentIndex = 0;
        loopView.setNotLoop();
        loopView.setItemsVisibleCount(5);
        loopView.setListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                mCurrentIndex = index;
            }
        });
        mChooseBankDialog.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mChooseBankDialog.dismiss();
            }
        });

        mChooseBankDialog.findViewById(R.id.confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mChooseBankDialog.dismiss();
                mBankCard.setText(list.get(mCurrentIndex));
            }
        });
    }
}
